class LandsController < ApplicationController
  before_filter :require_user
  
  def index
    @lands = Land.all
    
    respond_to do |format|
      format.html
      format.xml { render :xml => @lands }
    end
  end
  
  def new
    @land = Land.new
    
    respond_to do |format|
      format.html
      format.xml { render :xml => @land }
    end
  end
  
  def edit
    @land = Land.find(params[:id])
  end
  
  def show
    @land = Land.find(params[:id])
    
    respond_to do |format|
      format.html
      format.xml  { render :xml => @land }
    end
  end
  
  def destroy
    @land = Land.find(params[:id])
    @land.destroy
    
    respond_to do |format|
      format.html { redirect_to(lands_url) }
      format.xml  { head :ok }
    end
  end
  
  def create
    @land = Land.new(params[:land])
    
    respond_to do |format|
      if @land.save
        flash[:notice] = "Le pays a été correctement ajouté."
        format.html { redirect_to(lands_url) }
        format.xml  { render :xml => @land, :status => :created, :location => @land }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @land.errors, :status => :unprocessable_entity }
      end
    end
  end
  
  def update
    @land = Land.find(params[:id])
    
    respond_to do |format|
      if @land.update_attributes(params[:land])
        flash[:notice] = 'Le pays a été correctement modifié.'
        format.html { redirect_to(lands_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @land.errors, :status => :unprocessable_entity }
      end
    end
  end
end
